package com.higold.cloud.ui.adapter

import android.annotation.SuppressLint
import android.content.Intent
import android.text.TextPaint
import android.text.style.ClickableSpan
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.higold.cloud.MyApplication
import com.higold.cloud.R
import com.higold.cloud.R.id.iv_shop
import com.higold.cloud.glide.GlideApp
import com.higold.cloud.mvp.model.bean.developList.Body
import com.higold.cloud.mvp.model.bean.developList.Data
import com.higold.cloud.ui.activity.ShopDetailActivity
import com.higold.cloud.utils.CircleTransform
import java.text.SimpleDateFormat
import java.util.*

/**
 *    author : lxz
 *    date   : 2019/8/13 15:30
 *    desc   :
 */

class DevelopAdapter(data: ArrayList<Body>) : BaseQuickAdapter<Body, BaseViewHolder>(R.layout.item_shop_develop, data) {

    override fun convert(helper: BaseViewHolder, item: Body) {
        helper.setText(R.id.tv_shop_name, item.shop_name)
                .setText(R.id.tv_address, item.address )
                .setText(R.id.tv_date, timet(item.createtime.toString()))
                .setText(R.id.tv_salesman, "开发业务员：" + item.saleman_name)

        GlideApp.with(MyApplication.context)
                .load(item.shop_pic)
                .placeholder(R.drawable.ic_load_p)
                .skipMemoryCache(true)
                .centerCrop()
                .transition(DrawableTransitionOptions().crossFade())
                .transform(CircleTransform(MyApplication.context))
                .thumbnail(0.5f)
                .into(helper.getView(R.id.iv_shop))

        helper.itemView.setOnClickListener {
            val intent = Intent(this.mContext, ShopDetailActivity::class.java)
            intent.putExtra("shopId", item.id)
            this.mContext.startActivity(intent)
        }
    }


    internal var clickableSpan: ClickableSpan = object : ClickableSpan() {
        override fun onClick(widget: View) {

        }

        override fun updateDrawState(ds: TextPaint) {

        }

    }

    @SuppressLint("SimpleDateFormat")
    fun timet(time: String): String {
        val sdr = SimpleDateFormat("yyyy年MM月dd日  HH:mm")
        val lcc = java.lang.Long.valueOf(time)
        val i = Integer.parseInt(time)
        return sdr.format(Date(i * 1000L))
    }


}
